package com.glsc.ngateway.common.base.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.logging.log4j.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

@AllArgsConstructor
@Getter
public enum OaHrmresourceStatusEnum {
    //Status状态字典：0：试用  1：正式  2：临时  3：试用延期  4：解聘  5：离职  6：退休  7：无效
    试用("试用", 0),
    正式("正式", 1),
    临时("临时", 2),
    试用延期("试用延期", 3),
    解聘("解聘", 4),
    离职("离职", 5),
    退休("退休", 6),
    无效("无效", 7),
    ;

    private static final Logger log = LoggerFactory.getLogger(OaHrmresourceStatusEnum.class);
    private String desc;
    private Integer code;

    public static List<Integer> aliveList = List.of(试用.getCode(), 正式.getCode(), 临时.getCode(), 试用延期.getCode());
    public static boolean isAlive(String codeStr){
        if(Strings.isBlank(codeStr)){
            return false;
        }
        Integer code = Integer.valueOf(codeStr);
        return 试用.getCode().equals(code) || 正式.getCode().equals(code) || 临时.getCode().equals(code) || 试用延期.getCode().equals(code);
    }

    // 根据值获取对应的枚举
    public static String fromCode(String codeString) {
        try {
            int code = Integer.valueOf(codeString);
            for (OaHrmresourceStatusEnum status : OaHrmresourceStatusEnum.values()) {
                if (status.code == code) {
                    return status.desc;
                }
            }
        } catch (Exception e){
            log.error("错误的状态{}", codeString);
        }
        return "";
    }
}
